<html xmlns:th="http://www.thymeleaf.org" lang="">
<head>
    <meta charset="utf-8">
    <title>注册</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="layui/css/layui.css" media="all">
    <link rel="stylesheet" href="lib/css/admin.css" media="all">
    <link rel="stylesheet" href="lib/css/login.css" media="all">
    <script type="text/javascript" src="lib/vue.js"></script>
    <script type="text/javascript" src="lib/Popup.js"></script>
    <script type="text/javascript" src="lib/jquery-3.5.1.js"></script>
    <!--    <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">-->
    <!--    <script src="bootstrap/js/bootstrap.min.js"></script>-->
    <script type="text/javascript" src="lib/axios.js"></script>
    <script type="text/javascript" src="layui/layui.js"></script>
    <link href="lib/css/index.css" rel="stylesheet">
    <!--    <script src="static.js"></script>-->

</head>
<body>


<div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display: none; padding: 50px 0;">
    <div class="layadmin-user-login-main" id="main">

        <div class="layadmin-user-login-box layadmin-user-login-header">
            <div class="alert alert-primary" role="alert">
                <h2>xxx 注册</h2>
            </div>
            <div class="alert alert-light" role="alert">
                <div style="text-align:center ; margin: 0 auto;">
                    XXXXXXXXXXXXXX
                </div>
            </div>

        </div>
        <div class="layadmin-user-login-box layadmin-user-login-body layui-form">
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-username"
                       for="LAY-user-login-nickname"></label>
                <input type="text" name="nickname" id="LAY-user-login-nickname" lay-verify="nickname" placeholder="昵称"
                       class="layui-input"
                       v-model="name">
            </div>
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-email"
                       for="LAY-user-login-cellemail"></label>
                <input type="text" name="cellemail" id="LAY-user-login-cellemail" lay-verify="phone" placeholder="电话号码"
                       class="layui-input"
                       v-model="phone">
            </div>
            <div class="layui-form-item">
                <div class="layui-row">
                    <div class="layui-col-xs7">
                        <label class="layadmin-user-login-icon layui-icon layui-icon-vercode"
                               for="LAY-user-login-vercode"></label>
                        <input type="text" name="vercode" id="LAY-user-login-vercode" lay-verify="required"
                               placeholder="验证码" class="layui-input" v-model="registerCode">
                    </div>
                    <div class="layui-col-xs5">
                        <div style="margin-left: 10px;">
                            <button type="button" class="layui-btn layui-btn-primary layui-btn-fluid"
                                    id="LAY-user-getsmscode" @click="sendCode">获取验证码
                            </button>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-password"
                       for="LAY-user-login-password"></label>
                <input type="password" name="password" id="LAY-user-login-password" lay-verify="pass" placeholder="密码"
                       class="layui-input"
                       v-model="pwd1">
            </div>
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-password"
                       for="LAY-user-login-repass"></label>
                <input type="password" name="repass" id="LAY-user-login-repass" lay-verify="required" placeholder="确认密码"
                       class="layui-input"
                       v-model="pwd2">
            </div>

            <div class="layui-form-item ">
                <input type="checkbox" id="checkbox" name="agreement"
                       title="<a href='agreement.html'>同意用户隐私协议</a>">
            </div>

            <div class="layui-form-item">
                <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="LAY-user-reg-submit" @click="register">
                    注 册
                </button>
            </div>
            <div class="layui-trans layui-form-item layadmin-user-login-other">
                <label>社交账号注册</label>
                <a href="javascript:;"><i class="layui-icon layui-icon-login-qq"></i></a>
                <a href="javascript:;"><i class="layui-icon layui-icon-login-wechat"></i></a>
                <a href="javascript:;"><i class="layui-icon layui-icon-login-weibo"></i></a>

                <a href="/login" class="layadmin-user-jump-change layadmin-link layui-hide-xs">用已有帐号登入</a>
                <a href="/login"
                   class="layadmin-user-jump-change layadmin-link layui-hide-sm layui-show-xs-inline-block">登入</a>
            </div>
        </div>
    </div>
</div>
<div class="layui-trans layadmin-user-login-footer">

</div>


<script src="lib/Popup.js" type="text/javascript"></script>
<script type="text/javascript">
    const vue = new Vue({
        el: '#LAY-user-login',
        data: {
            name: "",
            pwd1: "",
            pwd2: "",
            phone: "",
            registerCode: "",
            judge: ""
        },
        methods: {
            //发送验证码
            sendCode: function () {
                let url = "/api/code/sendSms.do";
                let param = new URLSearchParams()
                param.append('name', this.name)
                param.append('phone', this.phone)
                axios({
                    method: 'post',
                    url: url,
                    data: param
                }).then(function (res) {
                    console.log(res)
                    if (res.data.code === 0) {
                        alertMy(res.data.msg)
                    } else {
                        alertMy(res.data.msg)
                    }
                    console.log(res);
                }).catch(function (error) {
                    console.log(error);
                });
            },
            register: function () {
                if (!$("input[type='checkbox']").is(':checked')) {
                    alertMy("请阅读并同意用户协议");
                    return;
                }
                if (this.pwd1 !== this.pwd2) {
                    alertMy("密码不一致");
                    return;
                }
                let url = "/api/user/register.do";
                let param = new URLSearchParams()
                param.append('name', this.name)
                param.append('pwd1', this.pwd1)
                param.append('pwd2', this.pwd2)
                param.append('phone', this.phone)
                param.append('registerCode', this.registerCode)
                axios({
                    method: 'post',
                    url: url,
                    data: param
                }).then(function (res) {
                    if (res.data.code === 0) {
                        alertLayer(res.data.msg, "/api/user/getUser.do")
                    } else {
                        alertMy(res.data.msg)
                    }
                    console.log(res);
                }).catch(function (error) {
                    console.log(error);
                });
            }
        }
    });


</script>
</body>
</html>
